/*
 * Copyright (c) 2014-2020 xmars All Rights Reserved.
 * ProjectName: xmars
 * ModuleName: framework-core
 * FileName: I18nMessageUtil.java
 * Author: YuZheng
 * Date: 2020/04/26 17:52:26
 * Version: 1.0
 * LastModified: 2020/04/26 15:07:26
 */

package com.topsun.framework.common.core.util;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * @className: I18nMessageUtil
 * @description:
 * @date: 2020/04/26 14:42
 * @since: 1.0
 */

public class I18nMessageUtil {

    private MessageSource messageSource;

    public I18nMessageUtil(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public String getMessage(String messageKey, Object[] messageArgs) {
        return messageSource.getMessage(messageKey, messageArgs, LocaleContextHolder.getLocale());
    }

    public String getMessage(String messageKey) {
        return getMessage(messageKey, null);
    }
}
